#include "Cooling.h"

Cooling::Cooling(uint8_t pin) : pin(pin), active(false) {
}

const error_t Cooling::begin() {
    pinMode(pin, OUTPUT);
    digitalWrite(pin, LOW);

    return NO_ERROR;
}

const bool Cooling::isActive() const {
    return this->active;
}

void Cooling::updateState(bool active) {
    if (this->active != active) {
        this->active = active;

        digitalWrite(pin, (uint8_t) (active ? HIGH : LOW));
    }
}

const error_t Cooling::tick(const tick_t ticks, const time_t time) {
    unsigned long hour = numberOfHours(time);

    // time range implementation (for testing only)
    updateState(hour >= 11 && hour <= 18);

    return NO_ERROR;
}

const bool Cooling::isSupported(String const &request) {
    return request.startsWith("CL");
}

const error_t Cooling::processCommand(String const &request, String &response) {
    return NO_ERROR;
}
